package f.h.dragon.patterns.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

/**
 * PersonDataMapper: person mapper
 * 
 * @author Wenlong Meng(wenlong.meng@gmail.com)
 * @version 1.0 at 2012/04/23
 * @since 1.0
 */
public class DefaultDataMapper<T> implements DataMapper<T> {
	
	//local variables
	/**
	 * logger
	 */
	private static Logger logger = Logger.getLogger(DefaultDataMapper.class);

	//Logic
	/**
	 * map resultSet to T
	 * 
	 * @param resultSet
	 * @return
	 */
	@Override
	public T mapRow(ResultSet resultSet) {
		Person bean = new Person();
		try {
			bean.setName(resultSet.getString("name"));
			bean.setAge(resultSet.getInt("age"));
			bean.setEmail(resultSet.getString("email"));
			bean.setTel(resultSet.getString("tel"));
			bean.setFlag(resultSet.getBoolean("flag"));
			return null;
		} catch (SQLException e) {
			logger.error(e);
			throw new RuntimeException(e);
		}

	}

}
